package com.isky.visual.interceptor;


import com.isky.visual.exception.GlobalException;
import com.isky.visual.result.CodeMsg;
import com.isky.visual.user.entity.User;
import org.springframework.core.NamedThreadLocal;

import java.util.Map;

/**
 * @author wenjs
 * 用户管理
 */
public class PlatformUserManager {
    private static final ThreadLocal<User> userMap = new NamedThreadLocal("user resources");

    public static void setUser(User user){
        userMap.set(user);
    }

    public static User getUser(){
       User user = userMap.get();
        if(user == null ){
            throw new GlobalException(CodeMsg.SESSION_ERROR);
        }
        return user;
    }
}
